package engine.content;

import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.xml.sax.InputSource;


public class XMLContent implements IContent<String,Document> {
	String contentType,contentBase, contentStr, description;
	Document domDoc;
	
	@Override
	public ContentTypes getType() {
		return ContentTypes.XML;
	}
	
	@Override
	public Document getContent() {
		return domDoc;
	}

	@Override
	public String getContentType() {
		return contentType;
		
	}

	@Override
	public void setContentType(String contentTypeStr) {
		this.contentType = contentTypeStr;
	}
	
	
	@Override
	public String getContentBase() {
		return contentBase;
		
	}

	@Override
	public void setContent(String content) throws Exception {
		this.contentStr=content;
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = dbf.newDocumentBuilder();
		InputSource is = new InputSource();
		is.setCharacterStream(new StringReader(this.contentStr));
		domDoc = db.parse(is);

	}

	@Override
	public void setContentBase(String contentBaseStr) {
	}

	@Override
	public String getContentAsString() {
		return this.contentStr;
	}
	
	@Override
	public String getFileSuffix() {
		return "xml";
	}
	@Override
	public String getDescription() {
		return this.description;
	}

	@Override
	public void setDescription(String setDescription) {
		this.description = setDescription;		
	}
}
